<template>

	<view class="change_recommender">
		<view class="c_box">
			<view class="c_box_tip">
				<view>变更说明：</view>
				<view>1.该会员不能有任何身份</view>
				<view>2.该会员没有产生过交易</view>
				<view>3.每个会员只有一次变更机会</view>
			</view>
			<view class="c_item" v-if="parenInfo">
				<image :src="parenInfo.avatar" mode=""></image>
				<view class="c_info">
					<view class="c_time">ID：{{parenInfo.id}}</view>
					<view class="c_time">手机号码：{{parenInfo.mobile}}</view>
					<view class="c_time">昵称：{{parenInfo.nickname}}</view>
				</view>
			</view>

			<view v-if="flag==0" class="top_search">
				<uni-easyinput prefixIcon="search" confirmType="search" @clear="search" primaryColor="#8615E1"
					:inputBorder="false" v-model="keywords" placeholder="搜索ID" @confirm="search">
					<template #right>
						<view class="t_search_btn" @click="search">搜索</view>
					</template>
				</uni-easyinput>
			</view>
			<view class="c_box_error" v-else>
				{{msg}}
			</view>
			<view v-if="open">
				<view class="c_item">
					<image :src="newParenInfo.avatar" mode=""></image>
					<view class="c_info">
						<view class="c_time">ID：{{newParenInfo.id}}</view>
						<view class="c_time">手机号码：{{newParenInfo.mobile}}</view>
						<view class="c_time">昵称：{{newParenInfo.nickname}}</view>
					</view>
				</view>
				<view class="f_buttons" @click="postChangeParent">变更推荐人</view>

			</view>

		</view>
		<!-- <uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-forms-item label="姓名" name="agentid">
				<input class="uni-input" @confirm="goregist" placeholder="请填写推荐人id" v-model="formData.agentid" />
			</uni-forms-item>
		</uni-forms>
		<button style="background-color: #8405dc;" @tap="goregist">提交</button> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {

				parenInfo: {},
				newParenInfo: {},
				keywords: '',
				flag: 0,
				msg: '',
				open: false
			}
		},
		onLoad() {
			this.getChangeInfo()
		},
		onShow() {

		},
		methods: {
			getChangeInfo() {
				this.$axios('info/changeInfo', 'GET', 'member').then(res => {
					if (res.data.code == 200) {
						this.parenInfo = res.data.data.parenInfo
						this.flag = res.data.data.flag
						this.msg = res.data.data.msg
					}
				})
			},
			// 搜索上级
			search() {
				this.$axios('info/parentInfo', 'GET', 'member', {
					pmid: this.keywords
				}).then(res => {
					if (res.data.code == 200) {
						this.newParenInfo = res.data.data.parenInfo
						this.open = true
					}
				})
			},
			postChangeParent(pmid) {
				let that=this
				uni.showModal({
					title: '提示',
					content: '是否变更推荐人？',
					success: function (res) {
						if (res.confirm) {
							that.$axios('info/changeParent', 'POST', 'member', {
								pmid: that.newParenInfo.id
							}).then(res => {
								if (res.data.code == 200) {
									that.getChangeInfo()
									that.open = false
									uni.showToast({
										title: '变更成功',
										icon: 'success',
										duration: 1500
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			}

		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #efefef;
		padding: 10rpx;
	}

	.f_buttons {
		background: linear-gradient(to right, #ff7101, #f03201);
		border-radius: 40upx;
		color: #fff;
		line-height: 70upx;
		letter-spacing: 2px;
		margin: 0 auto;
		text-align: center;
		width: 90%;
	}

	.c_box {
		background-color: #fff;
		.c_box_tip{
			color: red;
			font-size: 30rpx;
			padding-left: 50rpx;
			line-height: 50rpx;
		}
		.c_box_error{
			font-size: 30rpx;
			color: firebrick;
			margin-left: 20rpx;
		}
	}

	.c_item {
		background: #fff;
		border-radius: 20upx;
		padding: 20upx;
		display: flex;
		margin: 10rpx 0 20rpx;
		align-items: center;
		color: #333;
		font-size: 30rpx;
	}

	 image {
		border-radius: 20upx;
		height: 120rpx;
		width: 120rpx;
		margin-right: 20rpx;
	}

	.c_i_name {
		flex: 1;

		.c_title {
			display: flex;
			align-items: center;
		}
	}

	.top_search {
		background: #f8f8fe;
		display: flex;
		align-items: center;
		padding: 20rpx 20rpx 0;
		// position: fixed;
		width: 100%;
		top: calc(var(--window-top) + 0rpx);
		z-index: 999;

		.uni-easyinput {
			background: #fff;
			border-radius: 70rpx;
			height: 80rpx;
			border: 2rpx solid $bg-color;
			padding: 0 20rpx 0 10rpx;
			margin-right: 30rpx;
			line-height: 1;
			overflow: hidden;

			.t_search_btn {
				display: flex;
				align-items: center;
				color: $bg-color;

				&:before {
					display: block;
					content: '';
					width: 2rpx;
					height: 42rpx;
					background: $bg-color;
					margin-right: 30rpx;
				}
			}
		}

		.uni-easyinput__content-input {
			line-height: 80rpx !important;
			height: 80rpx !important;
		}

		.tit {
			font-size: 32rpx;
			font-weight: bold;
			margin-left: 30rpx;
		}
	}
</style>